package com.easy.concert.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.common.bean.ConresultBean;
import com.easy.common.service.IConresultService;
import com.easy.concert.mapper.ConresultMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService // dubbo服务
public class ConresultServiceImpl extends
        ServiceImpl<ConresultMapper, ConresultBean> implements IConresultService {
    @Override
    public ConresultBean getConresultById(Integer id) {
        return super.getById(id);
    }

    @Override
    public Integer addConresult(ConresultBean conresultBean) {
        if(super.save(conresultBean))
            return 1;
        else
            return 0;
    }

    @Override
    public Integer updateConresult(ConresultBean conresultBean) {
        return super.updateById(conresultBean)?1:0;
    }

    @Override
    public Integer deleteConresult(Integer id) {
        return super.removeById(id)?1:0;
    }

    @Override
    public List<ConresultBean> getAll(ConresultBean conresultBean) {
        LambdaQueryWrapper<ConresultBean> queryWrapper = new LambdaQueryWrapper<>();
        return super.list(queryWrapper);
    }

    @Override
    public IPage<ConresultBean> getPage(ConresultBean conresultBean,IPage page) {
        LambdaQueryWrapper<ConresultBean> queryWrapper = new LambdaQueryWrapper<>();
        if(conresultBean!=null && conresultBean.getId()!=null && conresultBean.getId().describeConstable().isEmpty()){
            queryWrapper.like(ConresultBean::getId,conresultBean.getId());
        }
        page.setTotal(super.count(queryWrapper));
        return super.page(page,queryWrapper);
    }
}
